import { reqGetSearchInfo } from "@/api"

//search的仓库
const state = {
  //初始化仓库
  searchList:{}
  
}
const mutations ={
  SEARCHLIST(state,searchList){
    state.searchList = searchList
  }
}
const actions = {
  async getSearchList({commit},params={}){
    let result = await reqGetSearchInfo(params);
   
    if(result.code == 200){
      commit('SEARCHLIST',result.data)
    }
  }
}
//计算属性，简化仓库中的数据
const getters = {
  //当前形参state，是当前仓库的state,不是大仓库中的state
  goodsList(state){
    //写上[]的原因是因为如果网络环境不好，state.searchList.goodsList返回的是undefined
    return state.searchList.goodsList || []
  },
  attrsList(state){
    return state.searchList.attrsList || []
  },
  trademarkList(state){
    return state.searchList.trademarkList || []
  }
}
export default {
  state,
  mutations,
  actions,
  getters
}